<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>产品分类管理</title>
    <link rel="stylesheet" href="css/font-awesome.min.css"/>
    <link rel="stylesheet" href="css/font-awesome-ie7.min.css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link href="css/jquery.datetimepicker.css" rel="stylesheet">
    <link rel="stylesheet" href="css/admin.css"/>

    <link rel="stylesheet" type="text/css" href="css/paging.css">

    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <![endif]-->
    <!--[if lt IE 10]>
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/jquery-placeholder/2.0.8/jquery.placeholder.min.js"></script>
    <![endif]-->
</head>
<body>
<div id="gray_bg"></div>
<!-- 编辑分类开始 -->
<div id="editDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11" id="diadogTitle"><span>编辑分类</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con">
        <div class="form-horizontal" role="form">
            <div class="form-group">
                <label for="inputPassword3" class="col-md-3 control-label">分类名称:</label>
                <div class="col-sm-9">
                    <input id="typeName" type="text" class="form-control">
                </div>
            </div>

            <div class="form-group" id="uploadImg">
                <label for="inputPassword3" class="col-md-3 control-label"><span
                        style="color: #e4393c">*</span>分类图标:</label>
                <div class="col-sm-4">
                    <button style="margin-bottom: 5px; margin-left: 0px" type="button" class="btn btn-default">上传图片
                    </button>
                    <input style="width:300px !important;height:60px !important;position: absolute !important;z-index: 100 !important;filter:alpha(opacity=0)!important;-moz-opacity:0 !important;-khtml-opacity:0 !important; opacity: 0 !important;top:0px; !important;cursor: pointer; left: 0px !important;"
                           id="pickfiles" type="file" class="form-control">
                    <input id="avatar" type="hidden" class="form-control">
                </div>
                <label class="control-label">(宽:80px，高:80px)</label>
            </div>
            <div class="form-group" id="imageShow">
                <label for="inputPassword3" class="col-md-3 control-label">图片:</label>
                <span class="col-sm-2" style=" color: #000; margin-top: 15px;"><img id="imgName"
                                                                                    style="width: 80px;height: 80px;"></span>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-md-3 control-label">分类说明:</label>
                <div class="col-md-9">
                    <textarea id="remark" class="form-control" style="height: 200px"></textarea>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-3 col-sm-9">
                    <button id="saveClass" type="submit" class="btn btn-danger">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 编辑分类结束 -->
<!-- 删除分类开始 -->
<div id="deleteDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11"><span id="delTitle">删除分类？</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con" style="padding:30px 0">

        <div class="form-horizontal" role="form">
            <div class="row">
                <div class="col-md-12"></div>

                <div class="form-group" style="text-align: center;">
                    <div class="col-md-1"></div>
                    <div class="col-md-2">
                        <button id="disableSure" type="submit" class="btn btn-primary">确 定</button>
                        <button id="enableSure" type="submit" class="btn btn-primary">确 定</button>
                    </div>
                    <div class="col-md-2">
                        <button id="btn-default" type="submit" class="btn btn-default">取 消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 删除分类结束 -->
<!-- header start -->
<div id="header" class="header">

</div>
<!-- header end -->
<!-- usercenter start -->
<div class="usercotent">
    <div id="center-left"></div>
    <div class="usercotentr floatr">
        <div class="user-tit" style="margin-bottom:10px">
            <h3>产品分类管理</h3>
        </div>
        <div class="usercotent-con">
            <div class="col-md-12">
                <button id="addCategory" type="button" class="btn btn-danger pull-right">添加分类</button>
            </div>


            <div class="down">
                <table  class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>类型名称</th>
                            <th>图标</th>
                            <th>备注</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="testMyGrid">
                    <!--<tr>-->
                        <!--<td>1</td>-->
                        <!--<td>测试类型</td>-->
                        <!--<td><img src="" alt=""></td>-->
                        <!--<td>测试类型</td>-->
                        <!--<td><a href="">分类内容</a>&nbsp;&nbsp;<a href="javascript:;" onclick="">编辑</a>&nbsp;&nbsp;<a href="javascript:;" onclick="">删除</a></td>-->
                    <!--</tr>-->
                    </tbody>
                </table>
            </div>
            <!-- page start -->
            <!--<nav class="totalpage floatr">-->
                <!--<span>总共</span><strong id="totalpage"></strong><span>条</span>-->
                <!--<div id="pageTool" style="margin-top:20px;"></div>-->
            <!--</nav>-->
            <!--<div class="clear"></div>-->
            <!-- page end -->
        </div>

    </div>
    <div class="clear"></div>
</div>

<!-- usercenter end -->

<!-- footer start -->
<div class="footer">
    <div class="bot">
        <p style="padding-top: 10px; text-align: center">Copyright (C) 都能印 2014-2016, all Rights Reserved | 豫ICP备14024464号-1 | 增值电信业务经营许可证：豫B2-20150019</p>
        <p class="authentication" style="padding-bottom: 10px; padding-top: 10px;">
            <img src="img/footer1.png" alt="">
            <img src="img/footer2.png" alt="">
            <img src="img/footer3.png" alt="">
            <img src="img/footer4.png" alt="">
            <img src="img/footer5.png" alt="">
        </p>
    </div>
</div>
<!-- footer end -->
<script src="js/jquery.min-1-11-3.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/widget/myDataGrid.js"></script>
<script src="js/widget/admin.js"></script>
<script type="text/javascript" src="js/query.js"></script>
<script type="text/javascript" src="js/paging.js"></script>
<script type="text/javascript" src="bower_components/plupload/js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
<script type="text/javascript" src="js/qiniu.min.js"></script>
<script type="text/javascript" src="js/upload.js"></script>
<script type="text/javascript">
    var id;
    //开始
    $(function () {
        initSideAccMenu("产品管理", "分类管理");
//        获取数据
        var url="apis/cuswx/getProductTypeManageList";

        $.ajax({
            url: url,
            type: 'post',
            data: JSON.stringify({}),
            dataType: 'json',
            async: false,
            contentType : 'application/json',
            success: function (data) {
//                console.log(data);
                if (data.httpCode == 200) {
                    var data=data.data;
//                    markDiv(data);
                    var html="";
                    for(var i=0;i<data.length;i++){
                        html +='<tr><td>'+data[i].id+'</td> ' +
                            '<td>'+data[i].typename+'</td> ' +
                            '<td><img src="'+data[i].icon+'" style="width: 80px;height: 80px"></td> ' +
                            '<td><span style="display: inline-block;width: 300px;height: auto;white-space: pre-wrap;">'+data[i].remark+'</span></td> ' +
                            ''+data[i].id+'<td><a href="product-managerlist.html?idtype=&typename=">分类内容</a>&nbsp;&nbsp;'+escape(data[i].typename)+'' +
                            '<a href="javascript:;" onclick="toEdit('+data[i].id+')">编辑</a>&nbsp;&nbsp;'


                        if(data[i].enable == 1){
                            html+='<a href="javascript:;" onclick="toDisable('+data[i].id+')">禁用</a></td></tr>'
                        }else if(data[i].enable == 0){
                            html+='<a href="javascript:;" style="color:#e4393c">已禁用</a> &nbsp;&nbsp;'
                            html+='<a href="javascript:;" onclick="toEnable('+data[i].id+')">启用</a></td></tr>'
                        }
                    }
                    $("#testMyGrid").append(html);

                } else {
                    alert(data.data);
                }

            }

        });






    });
    //编辑分类
    function toEdit(id) {
        $("#editDiadog").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#gray_bg").show();
        $("#editDiadog").center();
        $("#diadogTitle").html("编辑分类");
        $("#saveClass").attr('disabled', false);
        $.ajax({
            url: "apis/cuswx/getProductType",
            type: 'post',
            data: JSON.stringify({"idType":id}),
            dataType: 'json',
            async: false,
            contentType : 'application/json',
            success: function (res) {
//                console.log(res);
                if(res.httpCode == 200){
                    $("#typeName").val(res.data.typename);
                    $("#imgName").attr("src",res.data.icon);
                    $("#remark").val(res.data.remark);
//
                }else {
//                    alert(res.msg);
                }
            }
        })
        $("#saveClass").click(function () {
            $("#saveClass").attr('disabled', true);
            var typename=$("#typeName").val();
            var icon =$("#imgName").attr("src");
            var remark =$("#remark").val();
//            console.log(remark);
            var data={"params":{
                "id":id,
                "typename":typename,
                "icon":icon,
                "remark":remark
            }
            }
//            console.log(data);
            $.ajax({
                url: "apis/cuswx/updateProductType",
                type: 'post',
                data: JSON.stringify(data),
                dataType: 'json',
                async: false,
                contentType : 'application/json',
                success: function (res) {
//                    console.log(res);
                    if(res.httpCode == 200){
                        alert("修改成功");
                        window.location.reload();
                    }else {
                        alert(res.msg);
                    }
                }
            })

        })
    }
//    禁用分类
    function toDisable(e) {
        $("#deleteDiadog").show();
        $("#deleteDiadog").center();
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#delTitle").html("禁用分类");
        $("#enableSure").hide();
        $("#disableSure").show();
        id=e;

    }
    $("#disableSure").click(function () {
        $.ajax({
            url: "apis/cuswx/disableProductType",
            type: 'post',
            data: JSON.stringify({idType:id}),
            dataType: 'json',
            async: false,
            contentType : 'application/json',
            success: function (res) {
//                console.log(res);
                if(res.httpCode == 200){
                    alert("禁用成功");
                    window.location.reload();
                }else {
                    alert(res.msg);
                }
            }
        })
    })
    //启用分类
    function toEnable(j) {
        $("#deleteDiadog").show();
        $("#deleteDiadog").center();
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#delTitle").html("启用分类");
        $("#enableSure").show();
        $("#disableSure").hide();
        id=j;

    }
    $("#enableSure").click(function () {
        $.ajax({
            url: "apis/cuswx/enableProductType",
            type: 'post',
            data: JSON.stringify({idType:id}),
            dataType: 'json',
            async: false,
            contentType : 'application/json',
            success: function (res) {
//                console.log(res);
                if(res.httpCode == 200){
                    alert("启用成功");
                    window.location.reload();
                }else {
                    alert(res.msg);
                }
            }})
    })
    //添加分类
    $("#addCategory").click(function () {
        $("#saveClass").attr('disabled', false);
        $("#editDiadog").show();
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#editDiadog").center();
        $("#diadogTitle").html("添加分类");
        $("#typeName").val("");
        $("#imgName").attr("src","");
        $("#remark").val("");
        $("#saveClass").click(function () {
            $("#saveClass").attr('disabled', true);
            var typename=$("#typeName").val();
            var icon =$("#imgName").attr("src");
            var remark =$("#remark").val();
//            console.log(remark);
            var data={"productType":{
                "typename":typename,
                "icon":icon,
                "remark":remark
            }
            }
//            console.log(data);
            $.ajax({
                url: "apis/cuswx/newProductType",
                type: 'post',
                data: JSON.stringify(data),
                dataType: 'json',
                async: false,
                contentType : 'application/json',
                success: function (res) {
//                    console.log(res);
                    if(res.httpCode == 200){
                        alert("添加成功");
                        window.location.reload();
                    }else {
                        alert(res.msg);
                    }
                }
            })

        })
    });


    //垂直居中
    jQuery.fn.center = function () {
        this.css("position","absolute");
        this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
        this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
        return this;
    }
    $("#editDiadog").center();
    $("#deleteDiadog").center();
    //取消、关闭
    $(".close,#btn-default").click(function () {
        $("#gray_bg").hide();
        $("#showDetail").hide();
        $("#deleteDiadog").hide();
        $("#editDiadog").hide();


    });
    $("#close").click(function () {
        $("#detil-t").empty();
        $("#detil-m").empty();
        $("#gray_bg").hide();
        $("#franchiseDiadog").hide();
        $("#deleteDiadog").hide();
        $("#editDiadog").hide();

    });
</script>
</body>
</html>